﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IsmsExplorer.Model.Projects;
using IsmsExplorer.Infrastructure;
using IsmsExplorer.Infrastructure.RepositoryFramework;

namespace IsmsExplorer.Application.Projects {
    public static class ProjectService {
        private static IProjectRepository _repository;
        private static IUnitOfWork _unitOfWork;

        static ProjectService() {
            _unitOfWork = new UnitOfWork();
            _repository = RepositoryFactory.GetRepository<IProjectRepository, Project>(_unitOfWork);
        }

        public static IList<Project> GetAllProjects() {
            return ProjectService._repository.FindAll();
        }

        public static void SaveProject(Project p) {
            ProjectService._repository[p.ID] = p;
            ProjectService._unitOfWork.Commit();
        }

        public static Project GetProjectByID(Project p) {
            if (p != null) {
                return _repository.FindBy(p.ID);
            } else {
                return null;
            }
        }

        public static Project GetProjectByName(string name) {
            if (!string.IsNullOrEmpty(name)) {
                return _repository.FindBy(name);
            } else {
                return null;
            }
        }

    } // end public static class ProjectService
}
